<?PHP
  $current_page = "user_update_response.php";
  $page_type = "A";
  require_once 'header.php';

  // Obtain information for the account to be updated
  $user_id = $_POST["user_id"];
  $password = $_POST["password"];
  $fname = $_POST["fname"];
  $lname = $_POST["lname"];
  $dob = $_POST["dob"];
  $street = $_POST["street"];
  $city = $_POST["city"];
  $state = $_POST["state"];
  $zip = $_POST["zip"];
  $email = $_POST["email"];
  $phone = $_POST["phone"];
  $gender = $_POST["gender"];
  $promo = $_POST["promo"];
  $account_type= $_POST["account_type"];


  $zip = $_POST["zip"];

  // Account type
  if ($account_type == "A") {
    $aflag = "y";
    $sflag = "n";
    $vflag = "n";
  }
  else if ($account_type == "S") {
    $aflag = "n";
    $sflag = "y";
    $vflag = "n";
  }
  else if ($account_type == "V") {
    $aflag = "n";
    $sflag = "n";
    $vflag = "y";
  }
  else {
    $aflag = "n";
    $sflag = "n";
    $vflag = "n";
  }

  $sql = "update USER_ACCT set UserId='$user_id', Password='$password', Fname='$fname', Lname='$lname', DOB='$dob', Street='$street', City='$city', 
          State='$state', Zip='$zip', Email='$email', Phone='$phone', Gender='$gender', Promo_Request='$promo', 
		  AFlag='$aflag', SFlag='$sflag', VFlag='$vflag' where UserId='$user_id'";

  $result_array = execute_sql_in_oracle($sql);
  $result = $result_array["flag"];
  $cursor = $result_array["cursor"];

  if (!$result){

    // Store fields for update form
    $_SESSION['input_user_id'] = $user_id;
    $_SESSION['input_password'] = $password;
    $_SESSION['input_fname'] = $fname;
    $_SESSION['input_lname'] = $lname;
    $_SESSION['input_dob'] = $dob;
    $_SESSION['input_street'] = $street;
    $_SESSION['input_city'] = $city;
    $_SESSION['input_state'] = $state;
    $_SESSION['input_zip'] = $zip;
    $_SESSION['input_email'] = $email;
    $_SESSION['input_phone'] = $phone;
    $_SESSION['input_gender'] = $gender;
    $_SESSION['input_promo'] = $promo;
    $_SESSION['input_account_type'] = $account_type;

    $update_error = 'User account('."<b><font color=\"black\">".$user_id."</font></b>".') update failed!';
    header("Location:user_update.php?update_error=$update_error");
  }
  else {
    // Account updated, redirect to user.php
    resetForm();
    $update_success = 'User account('."<b><font color=\"black\">".$user_id."</font></b>".') updated successfully!';
    header("Location:user.php?update_success=$update_success");
  }
?>